package com.administrator.cloudapplication.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.administrator.cloudapplication.R;
import com.administrator.cloudapplication.adapter.MediaAdapter;
import com.administrator.cloudapplication.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 程序的第二个页面，显示媒体资讯。
 * 本页面由一个TabLayout绑定ViewPager而成。
 * ViewPager由一个fragment（VideoFragMent）循环三次生成。
 */

public class MediaFragment extends BaseFragment {
    View mView;
    TabLayout mTabLayout;
    ViewPager mViewPager;
    MediaAdapter mMediaAdapter;
    List<Fragment> mFragmentList = new ArrayList<>();
    VideoFragment videoFragment;

    @Override
    protected View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_media, container, false);
        return mView;
    }

    @Override
    protected void initPrepare() {

    }

    @Override
    protected void onInvisible() {

    }

    @Override
    protected void initData() {
        mTabLayout = (TabLayout) mView.findViewById(R.id.tl_media);
        mViewPager = (ViewPager) mView.findViewById(R.id.vp_media);
        for (int i = 0; i < 3; i++) {
            videoFragment = new VideoFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("type", i);
            videoFragment.setArguments(bundle);
            mFragmentList.add(videoFragment);
        }
        mMediaAdapter = new MediaAdapter(getChildFragmentManager(), mFragmentList);
        mViewPager.setAdapter(mMediaAdapter);
        mViewPager.setCurrentItem(0);
        mTabLayout.setupWithViewPager(mViewPager);
    }
}
